﻿// See https://aka.ms/new-console-template for more information
using GenerateProtocol;
using GenerateProtocol.Models;
using Microsoft.Extensions.Configuration;
using SqlSugar;

Console.WriteLine("=========================    RUNING    =========================");
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("application.json", optional: true, reloadOnChange: true);

SqlSugarClient _sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
{
    ConnectionString = builder.Build().GetConnectionString("DbConnection"),
    DbType = DbType.MySql,
    IsAutoCloseConnection = true
});

// sql日志输出
_sqlSugarClient.Aop.OnLogExecuting = (sql, pars) =>
{
    var sqllog = builder.Build().GetSection("SqlLog").Value;
    if (Convert.ToBoolean(sqllog))
        Console.WriteLine(sql + "\r\n" + _sqlSugarClient.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
};

var protocolGenerate = new ProtocolGenerate(_sqlSugarClient);
var count = _sqlSugarClient.Queryable<SupeSpaceitems>().Count();

for (int i = 0; i <= count; i++)
{
    Console.WriteLine($"PROGRESS : itemId[{i}]");
    var xml = protocolGenerate.ScriptProtocolGenerate(i);
}

Console.WriteLine("=========================    RUNING    =========================");
Console.ReadLine();

